/*
 * @features: 功能
 * @description: 说明
 * @Date: 2021-10-10 00:14:07
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-10-10 00:25:56
 * @LastEditors: judu233
 */
import ExtendsLoad from "../CCExtends";
declare global {
    interface Date {
        format(format: any): any;
    }
    interface DateConstructor {
        timeNow(): number;
        timeNowMillisecons(): number;
    }
}



class DateConstructorExtends {
    timeNow() {
        return Math.floor(Date.timeNowMillisecons() / 1000);
    }
    /**返回当前时间的毫秒数 */
    timeNowMillisecons() {
        let now = new Date();
        return now.getTime();
    }
}

class DateExtends {
    format(format) {
        let self = this as unknown as Date;
        var date = {
            "M+": self.getMonth() + 1,
            "d+": self.getDate(),
            "h+": self.getHours(),
            "m+": self.getMinutes(),
            "s+": self.getSeconds(),
            "q+": Math.floor((self.getMonth() + 3) / 3),
            "S+": self.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (self.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
                    date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    };
}

ExtendsLoad.load(Date.prototype, DateExtends);
ExtendsLoad.load(Date, DateConstructorExtends);
